import 'package:flutter/material.dart';
import 'package:freemusic/components/InkWellContainer.dart';
import 'package:freemusic/model/Gedan.dart';
import 'package:freemusic/services/GedanServices.dart';
import 'package:freemusic/utils/Util.dart';

enum Action { Ok, Cancel }

class GedanModalBottomSheet extends StatelessWidget {
  final Gedan _gedan;
  final double _containerHeight = 60;
  final double _iconSize = 24.0;

  GedanModalBottomSheet(this._gedan);

  void _handleDeleteOnTap(BuildContext context) {
    Color wordColor = Util.themeColor;
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text("提示"),
            content: Text("是否要删除当前歌单？"),
            actions: <Widget>[
              FlatButton(
                child: Text(
                  "取消",
                  style: TextStyle(color: wordColor),
                ),
                onPressed: () {
                  Navigator.pop(context, Action.Cancel);
                },
              ),
              FlatButton(
                child: Text(
                  "确认",
                  style: TextStyle(color: wordColor),
                ),
                onPressed: () {
                  GedanServices.getInstace().deleteGedan(this._gedan).then((v) {
                    if (v) {
                      Navigator.of(context).pop(1);
                      Navigator.of(context).pop(1);
                    }
                  });
                },
              ),
            ],
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    String gedanName = this._gedan.gdName;
    Color wordColor = Util.wordColor;
    double _containerHeight = this._containerHeight;
    int gedanCount = this._gedan.count;
    double _iconSize = this._iconSize;
    return Container(
      height: 180,
      child: Column(
        children: <Widget>[
          Container(
            height: _containerHeight,
            padding: EdgeInsets.all(8),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  width: 0.4,
                  color: Color.fromRGBO(200, 200, 200, 1),
                ),
              ),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Text(
                  gedanName,
                  style: TextStyle(fontSize: 18),
                ),
                Text(
                  "$gedanCount 首",
                  style: TextStyle(fontSize: 12, color: wordColor),
                ),
              ],
            ),
          ),
          InkWellContainer(
            
            image: Image.asset(
              "images/bianji.png",
              width: _iconSize,
            ),
            text: "编辑",
          ),
          InkWellContainer(
            image: Image.asset(
              "images/delete.png",
              width: _iconSize,
            ),
            text: "删除",
            onTap: () {
              this._handleDeleteOnTap(context);
            },
          ),
        ],
      ),
    );
  }
}
